package svc

import (
	"jinrigaoping/rpc/sys/internal/config"
	"jinrigaoping/rpc/sys/internal/model"

	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config config.Config

	SysUserModel     model.SysUserModel
	SysDictModel     model.SysDictModel
	SysDictItemModel model.SysDictItemModel
	SysRoleModel     model.SysRoleModel
	SysMenuModel     model.SysMenuModel
	SysRoleMenuModel model.SysRoleMenuModel
}

func NewServiceContext(c config.Config) *ServiceContext {

	sqlConn := sqlx.NewMysql(c.Mysql.Datasource)

	return &ServiceContext{
		Config:           c,
		SysUserModel:     model.NewSysUserModel(sqlConn),
		SysDictModel:     model.NewSysDictModel(sqlConn, c.CacheRedis),
		SysDictItemModel: model.NewSysDictItemModel(sqlConn, c.CacheRedis),
		SysRoleModel:     model.NewSysRoleModel(sqlConn),
		SysMenuModel:     model.NewSysMenuModel(sqlConn),
		SysRoleMenuModel: model.NewSysRoleMenuModel(sqlConn),
	}
}
